package com.sm.healthy.model

import androidx.lifecycle.viewModelScope
import com.sm.healthy.base.App
import com.sm.healthy.data.bean.UserEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.requestNoCheck

class UserCenterViewModel : BaseViewModel() {


    private val dao = App.database.userDao()

    fun getCustomers() = dao.getCustomers()

    fun getUserList(refresh: Boolean, action: (List<Any>) -> Unit) {
        // TODO: 2021/12/3 获取数据
        //模拟异步获取数据
        requestNoCheck({
            getList()
        }, {
            action(it)
        })
    }

    fun deleteUser(user: UserEntity) {
        viewModelScope.launch {
            dao.delete(user)
        }
    }


    private suspend fun getList(): List<Any> = withContext(Dispatchers.IO) {
        arrayListOf("", "")
    }
}